package com.exam.pinduoduo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution013 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        if(N < M){
            System.out.println(-1);
            return;
        }
        ArrayList<int[]> attacker = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            int d = scanner.nextInt();
            attacker.add(new int[]{a, d});
        }
        ArrayList<int[]> defender = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            int a = scanner.nextInt();
            int d = scanner.nextInt();
            defender.add(new int[]{a, d});
        }
        Collections.sort(attacker, (a1, a2) -> a1[0] == a2[0] ? a2[1] - a1[1] : a2[0] - a1[0]);
        Collections.sort(defender, (a1, a2) -> a1[1] == a2[1] ? a2[0] - a1[0] : a2[1] - a1[1]);
        int count = 0;
        for (int i = 0; i < M; i++) {
            if(attacker.get(0)[0] < defender.get(i)[1]){
                System.out.println(-1);
                return;
            }
            int thresh = defender.get(i)[0];
            int dispatch = -1;
            for (int j = 0; j < attacker.size(); j++) {
                if(attacker.get(j)[0] < defender.get(i)[1]){
                    break;
                }
                int def = attacker.get(j)[1];
                if(def > thresh){
                    if(dispatch == -1 || attacker.get(dispatch)[1] > def){
                        dispatch = j;
                    }
                }
            }
            if(dispatch != -1){
                count++;
                attacker.remove(dispatch);
            }
        }
        System.out.println(count);
    }
}
